<?php
namespace app\app\controller\v1;
use think\Db;
class PlaneController extends  BaseController{

    /**
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 机票
     */
    public function PlaneTicket()
    {
          $time = date('Y-m-d',time());   //当前时间
          $posttime = input('post.time');     //获取到的时间
          $plane_id = input('post.plane_id');
          $data = isset($posttime) ? $posttime : $time;
          $datastr = strtotime($data);
          $before = $datastr-259200;
          $after = $datastr+259200;
          $res = Db::name('plane_date')->where('date',['>',$before],['<',$after],'and')
              ->where('plane_id','eq',$plane_id)->select();
            foreach ($res as $k => $v){
                $res[$k]['date'] = date('m/d',$v['date']);
                $res[$k]['day'] = date('d',$v['date']);
            }
          return json_code(200,'success',$res);
    }

    /**
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 航班信息
     */
    public function PlaneInfo()
    {
        $plane_id = input('post.plane_id');
        $res = Db::name('plane')->find($plane_id);
        return json_code(200,'success',$res);


    }

    /**
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 列表
     */
    public function PlaneList()
    {
        $cid = input('post.cid');
        $pageindex = input('post.pageindex');
        $pagesize = input('post.pagesize');
        if( $pageindex <= 0 ){
            $length = 0;
        }else{
            $length = $pagesize*$pageindex;
        }
        $res = Db::name('plane')->where(['cid'=>$cid,'status'=>1])->limit($length,$pagesize)->select();
        return json_code(200,'success',$res);

    }



}